home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
ACKSRC.ZIP
/
ACKASM.240
< prev
next >
Wrap
Text File
|
1993-06-19
|
16KB
|
618 lines
PAGE 80,132
TITLE - XTASM.ASM - Assembly routines for 3D engine
;;;.286P
;==============================================================================
; COMMAND LINE ASSEMBLY
; MASM /B63 /Z /D_Mx FILENAME;
;
; WHERE Mx SPECIFIES MODEL (l OR c) FOR LARGE OR COMPACT MODELS
;==============================================================================
INCLUDE ET.EQU
INCLUDE ET.MAC
ANGLE_30 equ 160
ANGLE_360 equ 1920
extrn _bMaps:DWORD
extrn _oMaps:DWORD
extrn _bdfp:DWORD
extrn _PageBegin:WORD
extrn _InvCosTable:DWORD
extrn _InvSinTable:DWORD
extrn _LongCosTable:DWORD
extrn _DistanceTable:WORD
extrn _AdjustTable:DWORD
extrn _CenterRow:WORD
extrn _MaxDistance:WORD
extrn _TopColor:WORD
extrn _BottomColor:WORD
extrn _lowmask:BYTE
extrn _Walls:WORD
extrn _xRay:NEAR
extrn _yRay:NEAR
extrn N_LDIV@:FAR
PUBLIC _graphinit
PUBLIC _usepage
PUBLIC _flippage
PUBLIC _SetPalette
PUBLIC _DrawWalls
PUBLIC _DrawOneObject
SC_INDEX equ 03c4h ;Sequence Controller Index
CRTC_INDEX equ 03d4h ;CRT Controller Index
MISC_OUTPUT equ 03c2h ;Miscellaneous Output register
SCREEN_SEG equ 0a000h ;segment of display memory in mode X
_TEXT segment byte public 'CODE'
DGROUP group _DATA,_BSS
assume cs:_TEXT,ds:DGROUP
_ViewPage dw 0 ; The address of the current view page
_WritePage dw 0 ; The address of the current write page
PageTable dw 4 dup (0) ; Address of 4 pages
ScreenWidth dw 320/4 ; The width of the screen
PageSize dw 320/4*240 ; The size of each page
CRTParms label word
dw 00d06h ;vertical total
dw 03e07h ;overflow (bit 8 of vertical counts)
dw 04109h ;cell height (2 to double-scan)
dw 0ea10h ;v sync start
dw 0ac11h ;v sync end and protect cr0-cr7
dw 0df12h ;vertical displayed
dw 00014h ;turn off dword mode
dw 0e715h ;v blank start
dw 00616h ;v blank end
dw 0e317h ;turn on byte mode
CRT_PARM_LENGTH equ (($-CRTParms)/2)
_TEXT ends
_DATA segment word public 'DATA'
; Index/data pairs for CRT Controller registers that differ between
; mode 13h and mode X.
_d@ label byte
_DATA ends
_BSS segment word public 'BSS'
_b@ label byte
_BSS ends
public _graphinit
public _ViewPage,_WritePage
public ScreenWidth,PageSize,PageTable
_TEXT SEGMENT byte public 'CODE'
ASSUME cs:_TEXT
;==============================================================================
; void graphinit(int width,int psize,int mask)
; width - width of the screen in bytes/plane (defaults to 320/4 if 0)
; psize - size of each page in bytes/plane (defaults to 320*200/4 if 0)
;==============================================================================
PBEGIN _graphinit
push bp
mov bp,sp
push si
push di
push ds
mov ax,cs
mov ds,ax
mov es,ax
mov bx,320/4
mov cs:[ScreenWidth],bx
mov bx,320/4*240
mov cs:[PageSize],bx
; Set up the page table
xor ax,ax
mov bx,cs:[PageSize]
lea di,cs:[PageTable]
mov cx,4
init4:
stosw
add ax,bx
loop init4
;;;;; mov word ptr cs:[PageTable+2],8000H
; Now set up the graphics mode
mov ax,13h
int 10h ; Set 320x200x256
mov dx,SC_INDEX
mov ax,0604h
out dx,ax ;disable chain4 mode
mov ax,0100h
out dx,ax ;synchronous reset while switching clocks
mov dx,MISC_OUTPUT
mov al,0e3h
out dx,al ;select 28 MHz dot clock & 60 Hz scanning rate
mov dx,SC_INDEX
mov ax,0300h
out dx,ax ;undo reset (restart sequencer)
mov dx,CRTC_INDEX ;reprogram the CRT Controller
mov al,11h ;VSync End reg contains register write
out dx,al ; protect bit
inc dx ;CRT Controller Data register
in al,dx ;get current VSync End register setting
and al,7fh ;remove write protect on various
out dx,al ; CRTC registers
dec dx ;CRT Controller Index
cld
mov si,offset CRTParms ;point to CRT parameter table
mov cx,CRT_PARM_LENGTH ;# of table entries
SetCRTParmsLoop:
lodsw ;get the next CRT Index/Data pair
out dx,ax ;set the next CRT Index/Data pair
loop SetCRTParmsLoop
mov dx,SC_INDEX
mov ax,0f02h
out dx,ax ;enable writes to all four planes
mov ax,SCREEN_SEG ;now clear all display memory, 8 pixels
mov es,ax ; at a time
sub di,di ;point ES:DI to display memory
sub ax,ax ;clear to zero-value pixels
mov cx,8000h ;# of words in display memory
rep stosw ;clear all of display memory
pop ds
pop di ;restore C register vars
pop si
pop bp ;restore caller's stack frame
ret
_graphinit endp
;==============================================================================
; void SetVGAmode(void);
;==============================================================================
PBEGIN _SetVGAmode
push bp
mov ax,13h
int 10h ; Set 320x200x256
pop bp
ret
_SetVGAmode endp
;==============================================================================
; void usepage(int page)
;==============================================================================
UPnum equ [bp+ABASE]
PBEGIN _usepage
push bp
mov bp,sp
mov bx,UPnum
and bx,3
shl bx,1
mov ax,cs:PageTable[bx]
mov cs:[_WritePage],ax
pop bp
ret
_usepage endp
;==============================================================================
; void flippage()
;
; NOTE: Some lines have been commented out for test purposes. If you experience
; flicker when the page flips, un-comment the lines waiting for vertical
; retrace.
;==============================================================================
PBEGIN _flippage
mov cx,cs:[_ViewPage]
xchg cx,cs:[_WritePage]
mov cs:[_ViewPage],cx ; An ISR will set the VGA at the next retrace
mov bh,0dH
mov bl,cl
mov dx,3dah
Ret1:
;;;; in al,dx
;;;; test al,1
;;;; jnz Ret1 ; Wait for display enable
; cli
mov al,0ch
mov ah,ch
mov dx,3d4h
out dx,ax ; set the displayed offset (high)
; inc al
; mov ah,cl
;;; mov ax,bx
;;; out dx,ax ; set the displayed offset (low)
; sti
;; mov dx,3dah
Ret2:
;; in al,dx
;; test al,8
;; jz Ret2 ; Wait for the video card to use the address just set
ret
_flippage endp
;==============================================================================
; void SetPalette(unsigned char far *PalBuf);
;==============================================================================
SPbuf equ [bp+ABASE]
PBEGIN _SetPalette
push bp
mov bp,sp
push ds
push si
lds si,dword ptr SPbuf
mov cx,256
xor bx,bx
cld
mov dx,3C8H
sp010:
mov al,bl
out dx,al
inc dx
lodsb
out dx,al
lodsb
out dx,al
lodsb
out dx,al
dec dx
inc bx
loop sp010
pop si
pop ds
pop bp
ret
_SetPalette endp
;==============================================================================
; void DrawWalls(void);
;==============================================================================
Y2 equ [bp-2]
AVLOW equ [bp-4]
AVHI equ [bp-6]
VCOL equ [bp-8]
BOFFLOW equ [bp-10]
BOFFHI equ [bp-12]
sColor equ [bp-14]
fColor equ [bp-16]
PBEGIN _DrawWalls
push bp
mov bp,sp
sub sp,18
push ds
push si
push di
mov dx,3c4H
mov ax,0F02H
out dx,ax ;Select map mask and all planes
mov bx,word ptr DGROUP:_MaxDistance ; Get max distance to wall
shl bx,1 ; Make a word index
mov ax,word ptr DGROUP:_DistanceTable[bx] ;Look up actual height
cmp ax,240 ; Full screen height?
jae drw000 ; Yes, nothing to fill in
and ax,0FFFEH ; Strip any odd values
mov bx,ax ; Save height
mov si,ax ; Again save height
shr bx,1 ; Get Height / 2
mov dx,120 ; Pick up our center row
sub dx,bx ; and sub ht/2
mov bx,dx ; Save new value
mov cl,6 ; Get ready to mult by 80
shl bx,cl ; first mult by 64
shl si,cl ; also mult the original ht
mov cl,4 ; No do a mult by 16
shl dx,cl ; to top layer
shl ax,cl ; and initial height
add bx,dx ; Add x64 and x16 for x80
add si,ax ; do same with height
mov ax,0A000H
mov es,ax
mov di,cs:_WritePage ;get start of buffer
mov ax,ds:_TopColor
mov ah,al
shr bx,1 ;only fill words
mov cx,b